<template>
  <el-container class="main_con" style="padding:0;">
    <div class="list_con" style="margin-top:0;">
      <el-table :data="list" fit highlight-current-row>
        <el-table-column prop="coupon_id" label="ID"></el-table-column>
        <el-table-column label="券名称">
          <template slot-scope="scope">
            {{ scope.row.coupon.name }}
          </template>
        </el-table-column>
        <el-table-column label="优惠内容">
          <template slot-scope="scope">
            满{{ scope.row.coupon.conditions }}减{{ scope.row.coupon.denomination }}
          </template>
        </el-table-column>
        <el-table-column label="领取时间" prop="create_time"></el-table-column>
        <el-table-column label="有效期">
          <template slot-scope="scope">
            <span v-if="scope.row.coupon.time_limit_type == 0">领取日内{{ scope.row.coupon.limit_time }}天有效</span>
            <span v-if="scope.row.coupon.time_limit_type == 1">{{ scope.row.coupon.limit_indate_begin }}-{{ scope.row.coupon.limit_indate_end }}</span>
          </template>
        </el-table-column>
        <el-table-column label="状态" prop="status_text">
          <template slot-scope="scope">
        <span>{{scope.row.status_text}}</span>
        <el-button v-if='scope.row.order_id' @click='todetail(scope.row)' type="text">查看订单</el-button>
        <!-- <el-link v-if='scope.row.used_type==1' :href="'#/order/list/item?id='+scope.row.order_id">查看订单</el-link> -->
        </template></el-table-column>
      </el-table>
      <div class="table_footer" style="display:flex;justify-content:flex-end;">
        <el-pagination @current-change="ChangeCurrent" hide-on-single-page class="pages" background layout="prev, pager, next" :total="total" :page-size="size"></el-pagination>
      </div>
    </div>
  </el-container>
</template>

<script>
import {userCouponList} from '@/api/mall/user';
export default {
  name: 'couponList',
  data() {
    return {
      isLoading: false,
      list: [],
      obj: {
        user_id: ''
        //coupon_id:'',
        //type:0,
        //status:'',
      },
      page: 1,
      size: 5,
      total: 0
    };
  },
  components: {},
  methods: {
    //初始化
    init(id) {
      this.obj.user_id = id;
      this.getData();
    },
    //搜索函数
    getData() {
      this.isLoading = true;
      userCouponList(this.obj, this.page, this.size)
        .then(res => {
          this.isLoading = false;
          this.list = res.msg.data;
          this.total = res.msg.total;
        })
        .catch(e => {
          this.isLoading = false;
        });
    },
    //切换页码
    ChangeCurrent(page) {
      this.page = page;
      this.getData();
    },
    todetail(o){
      if(o.used_type==1){
        this.$router.push({path: '/order/list/item', query: {id: o.order_id, k: Math.random()}});
        
        // this.$router.push('order/list/item',query:{
        //   id:o.order_id
        // })
      }
    }
  }
};
</script>

<style lang="scss" scoped></style>
